#!/usr/bin/env bash
# Copyright (C) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See LICENSE in project root for information.

# This file is a hack for creating the environment tgz with conda installed in
# the right place (cannot install it in one place and use in another).  It would
# be better to do this using a docker multi-stage build, but there is no way to
# tag the intermediate step so it won't be deleted with a `docker system prune`.
# By using a tgz we properly control the caching.

apt-get update --fix-missing
apt-get install -y curl unzip bzip2 libopenmpi1.10 libgomp1 libunwind8 libtiff5 binutils

export USER="mmlspark"
export HOME="/home/$USER"

echo 'PS1='\''\u:\w\$ '\' >> "/etc/skel/.bashrc"
useradd -c "Microsoft ML for Apache Spark" -U -d "$HOME" -m "$USER"
cd "$HOME"

# avoid running git
/mkenv/src/runme BUILDMODE=runtime INSTALLER_CACHE_DIR=/mkenv/cache \
                 MML_VERSION="???" MML_BUILD_INFO="???" MML_LATEST="???"

chown -R "$USER:$USER" "$HOME"
cd /home
tar czf "$USER.tgz" "$USER"
rm -rf "$USER"
chown -R "$USER:$USER" "$USER.tgz"
